package P1.qujianhebing;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @Date : 2023-03-02
 * @Description:区间合并
 */
public class MergeInterval {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
       List<P> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            list.add(new P(l,r));
        }
        int merge = merge(list);
        System.out.println(merge);
    }
    public static int merge(List<P> list){
        list.sort((o1,o2) -> o1.x-o2.x);
        List<P> ans= new ArrayList<>();
        int l=Integer.MIN_VALUE,r=Integer.MIN_VALUE;

        for(P e:list){
            if(r<e.x){
                if(r!=Integer.MIN_VALUE)
                    ans.add(new P(l,r));
                l=e.x;
                r=e.y;
            }else{
                r=Math.max(r,e.y);
            }
        }
        if(r!=Integer.MIN_VALUE) ans.add(new P(l,r));
        return ans.size();
    }
}
class P{
    int x,y;
    public P(int x,int y){
        this.x=x;
        this.y=y;
    }
}
